<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<jsp:include page="/public/template/header.jsp" />


<style type="text/css">
input.text {
	width: 400px;
}

input.button {
	width: 80px;
}

table,td,tr,th {
	border-style: solid;
	border-width: 1px;
	border-color: black;
	margin: 0;
	border-collapse: collapse;
	padding: 6px;
}

#content {
	padding: 10px;
}
</style>


<div id="content">

	<h1>WebHooks: List All</h1>

	<button  id="newButton" style="position: absolute; width: 100px; height: 40px; margin-bottom: 100px; font-size:large; font:black;">New</button>
	<div style="position: absolute; top: 150px; width: 100%;">
		<table style="position: absolute; width: 90%">
			<tr>
				<th>URL</th>
				<th>Description</th>
				<th>Return Type</th>
				<th>Edit</th>
				<th>Delete</th>
			</tr>

			<c:forEach items="${webhooks}" var="wh">
				<tr>
					<td>${wh.url}</td>
					<td>${wh.sourceDescription}</td>
					<td>${wh.returnType}</td>
					<td><button class="editButton"  value="${wh.id}" >Edit</button></td>
					<td><button class="deleteButton" name="${wh.url}" value="${wh.id}">Delete</button></td>
				</tr>
			</c:forEach>

		</table>

	</div>

</div>



<script type="text/javascript">
	$(function() {
		$("#newButton").click(function(){
			var url = "<c:url value='/config/webHooks/new'/>";
			$(location).attr('href',url);
		});
		
		$(".deleteButton").click(function(){
			var decisao = confirm("Are you sure? \n WebHook "+$(this).attr("name")+" will be permanently deleted!");
			if(decisao)
			{
				var url = "<c:url value='/config/webHooks/'/>"+$(this).attr("value")+"/delete";
				$(location).attr('href',url);
			}
		});
		
		$(".editButton").click(function(){
			var url = "<c:url value='/config/webHooks/'/>"+$(this).attr("value");
			$(location).attr('href',url);	
		});
		
		
	});
</script>


<jsp:include page="/public/template/footer.jsp" />
